package per.liu.dao.impl;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import per.liu.dao.DealDao;
import per.liu.model.mapper.DealMapper;
import per.liu.model.pojo.Deal;
import per.liu.model.pojo.DealExample;

import java.util.List;

/**
 * Created by Administrator on 2015/2/11.
 */
@Component
public class DealDaoImpl extends SqlSessionDaoSupport implements DealDao {

	@Autowired(required = false)
	private DealMapper dealMapper;

	/**
	 * 测试直接调用DealMapper.xml里面的代码，成功
	 * @param deal
	 */
	@Override public void update(Deal deal) {
		getSqlSession().update("per.liu.model.mapper.DealMapper.updateByPrimaryKeySelective",deal);
//		dealMapper.updateByPrimaryKeySelective(deal);
//		throw new RuntimeException("exception in dao");
	}

	@Override public List<Deal> findAll() {
		return dealMapper.selectByExample(new DealExample());
	}

	@Override public Deal findById(Integer id) {
		return dealMapper.selectByPrimaryKey(id);
	}
}
